<?php
session_start();
$title="Check-Out ห้องพัก";
include ('header-admin.php');

$userID=$_SESSION["HBD_USER"];
$countTopic=0;
//if($userID == 1){
?>
<script language="javascript">
	function ConfirmChoice(room_id,reserv_id){
	answer = confirm("คุณแน่ใจว่าจะ Check-Out ?");
		if (answer !=0)
			location = "doCheckOut.php?ref=1&room_id=" + room_id + "&reserv_id=" + reserv_id;
	}
	function submitCheckout(){
		var listReservId = new Array();
		var listRoomId = new Array();
	    jQuery("input[id='reserv_id']:checkbox:checked").each(function(){
	    	var reserv_id = this.value;
	    	listReservId.push(reserv_id);
	    	jQuery("input[id='"+reserv_id+"']:hidden").each(function(){
		    	var room_id = this.value;
	    		listRoomId.push(room_id);
		    });
	    });
        $("input[id='checkout_reserv_id']:hidden").val(listReservId);
        $("input[id='checkout_room_id']:hidden").val(listRoomId);
/*         $("#checkout_reserv_id").val(listReservId); */
/*         $("#checkout_room_id").val(listRoomId); */
        $('#checkout').submit();
	}
	function onToggle(id){
/* 		$('table.'+id).show(); */
		if($('table#'+id).is(":visible")){
			$('table#'+id).hide();
		}else{
			$('table#'+id).show();
		}
	}

</script>
<?//}?>
<div id="center-block" class="main-content">
<img src="img/door_checkout.png"/ id="img-block-content">
<div id="content-title-right">
		<h2 class="caption-header">Check-Out ห้องพัก</h2>
		<span class="caption">แสดงห้องทั้งหมด เพื่อ Check-Out</span>
		<span class="right-button">
		<form method="POST" action="listRoom.php"><input type="submit" value="รายการห้องพัก" class="button"></form>
				</span>
	</div>

	<hr>
		<?
	//$sql="SELECT room_id,roomsize_name,roomtype_name,room_cost,room_status 
   //FROM resort,roomsize,roomtype
   //WHERE roomsize.roomsize_id = resort.roomsize_id AND roomtype.roomtype_id = resort.roomtype_id AND room_status != '0' ORDER BY resort.room_id ASC";
$current = date("Y-m-d",strtotime("Today"));

   /*$sql="SELECT *
   FROM resort
   INNER JOIN  roomsize ON (resort.roomsize_id = roomsize.roomsize_id)
   INNER JOIN  roomtype ON (resort.roomtype_id = roomtype.roomtype_id)
   INNER JOIN reservation ON (resort.room_id = reservation.room_id)
   WHERE room_status != '0' AND reserv_status = '1' 
   ORDER BY resort.room_id ASC";*/
	$sql_reservgroup = "SELECT reservgroup.reserv_gid AS reserv_gid,reservation.reserv_id,reservation.room_id,customer.customer_name AS customer_name,customer.customer_surname AS customer_surname,reservgroup.room_list AS room_list,reservgroup.reserv_gcost AS reserv_gcost
	FROM reservgroup
	INNER JOIN  reservation ON (reservgroup.reserv_gid = reservation.reserv_gid)
	INNER JOIN customer ON (reservation.id = customer.id)
	WHERE reservation.reserv_status = '4' GROUP BY reservgroup.reserv_gid";
	$result_reservgroup = mysql_query($sql_reservgroup);
?>
		<table summary="webboard about Datastrucutre learning" id="table_checkout">
<!-- 		<thead> -->
<!-- 		<tr class="odd"> -->
			<th scope="col" abbr="reserv_id">เลขที่จอง</th>
			<th scope="col" abbr="customer_id">ชื่อ-นามสกุล ผู้จอง</th>
			<th scope="col" abbr="room_id">หมายเลขห้องพัก</th>
<!-- 			<th scope="col" abbr="reserv_end">ชนิดห้อง</th> -->
<!-- 			<th scope="col" abbr="reserv_begin">ขนาดห้อง</th>	 -->
			<th scope="col" abbr="room_id">ราคา</th>
			<!--<th scope="col" abbr="customer_id">สถานะ</th>-->
<!-- 			<th scope="col" abbr="customer_name">จัดการ</th> -->
<!-- 		</tr>	 -->
<!-- 		</thead> -->
<?
while ($rs_reservgroup = mysql_fetch_array($result_reservgroup)){
	$countTopic++;
			if($countTopic%2==0)
				echo "<tr class='odd' onClick='onToggle(".$rs_reservgroup['reserv_gid'].");'>";
			else
				echo "<tr class='even' onClick='onToggle(".$rs_reservgroup['reserv_gid'].");'>";
/* 	echo "<tr onClick='onToggle(".$rs_reservgroup['reserv_gid'].");'>"; */
	echo "<td>".$rs_reservgroup['reserv_gid']."</td>";
	echo "<td>".$rs_reservgroup['customer_name']." ".$rs_reservgroup['customer_surname']."</td>";
	echo "<td>".$rs_reservgroup['room_list']."</td>";
	echo "<td>".$rs_reservgroup['reserv_gcost']."</td>";
	echo "</tr>";
/* 	echo "</table>"; */
	/*
echo '</table>
	<form action="#" method="POST" >
	<table id="table" class="'.$rs_reservgroup['reserv_gid'].'">
	<tbody>';
*/
?>
	
<?
	$reservgroup = $rs_reservgroup['reserv_gid'];
	$sql_temproom ="SELECT reservgroup.reserv_gid AS reserv_gid,
	reservation.reserv_id AS reserv_id,
	reservation.room_id AS room_id,
	customer.customer_name AS customer_name,
	customer.customer_surname AS customer_surname,
	roomtype.roomtype_name AS roomtype_name,
	roomsize.roomsize_name AS roomsize_name,
	resort.room_cost AS room_cost,
	resort.room_status AS room_status
	FROM reservgroup
	INNER JOIN  reservation ON (reservgroup.reserv_gid = reservation.reserv_gid)
	INNER JOIN customer ON (reservation.id = customer.id)
	INNER JOIN resort ON (reservation.room_id = resort.room_id)
	INNER JOIN  roomsize ON (resort.roomsize_id = roomsize.roomsize_id)
   	INNER JOIN  roomtype ON (resort.roomtype_id = roomtype.roomtype_id)
	WHERE reservgroup.reserv_gid = $reservgroup AND reservation.reserv_status = '4'";
	$result_temproom = mysql_query($sql_temproom);
	echo '<tr ><td colspan="4"><table class="table" id="'.$rs_reservgroup['reserv_gid'].'" style="width:100%">
	<tbody>';
	while($rs_temproom = mysql_fetch_array($result_temproom)){
		if($rs_temproom['room_status']==0)$status = '<img src="img/bullet_green.png">';
		if($rs_temproom['room_status']==1)$status = '<img src="img/bullet_red.png">';
			$countTopic++;
			if($countTopic%2==0)
				echo '<tr class="odd">';
			else
				echo '<tr class="even">';
			echo '<td><input type="checkbox" id="reserv_id" value="'.$rs_temproom['reserv_id'].'"></input></td>';
/* 			echo '<td>' . $rs_temproom['reserv_gid'] . '</td>'; */
/* 			echo '<td>' . $rs_temproom['customer_name'] . ' '.$rs_temproom['customer_surname'].'</td>'; */
			echo '<td>' . $rs_temproom['room_id'] . '<input type="hidden" id="'.$rs_temproom['reserv_id'].'" value="'.$rs_temproom['room_id'].'"></td>';
			echo '<td>' . $rs_temproom['roomtype_name'] . '</td>';
			echo '<td>' . $rs_temproom['roomsize_name'] . '</td>';
/* 			echo '<td>' . $rs_temproom['room_cost'] . '</td>'; */
	}
	echo '</tbody></table></td></tr>';
}	
	?>
	</table>
	<form action="doCheckOut.php" method="POST" id="checkout">
	<input type="hidden" id="checkout_reserv_id" name="checkout_reserv_id" value="">
	<input type="hidden" id="checkout_room_id" name="checkout_room_id" value="">
	<p class="submit" style="text-align: right;"><input type="button" value="ยืนยันการเช็คเอาท์" onclick="submitCheckout();" /></p><br>
	</form>
	</div>
	<script language="javascript">
		$('table.table').hide();
		
	</script>

<?
include ('footer.php');
?>